<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>老师信息</title>
    <style>
        #container {
            width: 80%;
            margin: 10px auto;
        }

        .teacher {
            width: 100%;
            margin: 0 auto;
            padding: 10px 0;
            border-bottom: 1px dashed gray;
            overflow: auto;
        }

        .teacher > div {
            float: left;
        }

        .photo {
        {#height: 140px;#} border-radius: 75px;
            overflow: hidden;
            margin-left: 20px;
        }

        .info {
            width: 75%;
            padding-left: 30px;
        {#margin-left: 30px;#}
        }

        .info div {
            clear: both;
            margin: 5px 10px;
        }

        .info span {
            margin-right: 25px;
        }

        .info a {
            text-decoration: none;
            color: darkcyan;
        }
    </style>
</head>
<body>
<div id="container">
    <h1>{{ subject.name }}学科的老师信息</h1>
    <hr>
    {% if not teachers %}
        <h2>暂无该学科老师信息</h2>
    {% endif %}
    {% for teacher in teachers %}
        <div class="teacher">
            <div class="photo">
                <img src="/static/images/{{ teacher.photo }}" height="400" alt="">
            </div>
            <div class="info">
                <div>
                    <span><strong>姓名：{{ teacher.name }}</strong></span>
                    <span>性别：{{ teacher.sex }}</span>
                    <span>出生日期：{{ teacher.birth }}</span>
                </div>
                <div class="intro">{{ teacher.intro }}</div>
                <div class="comment">
                    <a href="/good/?tno={{ teacher.no }}">好评</a>&nbsp;(<strong>{{ teacher.good_count }}</strong>)
                    &nbsp;&nbsp;&nbsp;&nbsp;
                    <a href="/bad/?tno={{ teacher.no }}">差评</a>&nbsp;(<strong>{{ teacher.bad_count }}</strong>)
                </div>
            </div>
        </div>
    {% endfor %}
    <a href="/">返回首页</a>
</div>

<script src="/static/js/jquery-3.4.1.js"></script>
<script>
    $(() => {
        $('.comment>a').on('click', (evt) => {
            evt.preventDefault()
            let url = $(evt.target).attr('href')
            $.getJSON(url, (json) => {
                if (json.code == 200) {
                    $(evt.target).next().text(json.count)
                } else {
                    alert(json.msg)
                }
            })
        })
    })
</script>
</body>
</html>